package com.common.baselib.mvp;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;



@SuppressWarnings("rawtypes")
public abstract class MvpBaseFragment<P extends MvpBasePresenter>
        extends Fragment implements IMvpBaseView {
    protected P presenter;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        presenter = createPresenter();
        if (presenter != null) {
            presenter.attachView(this);
        }
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (presenter != null) {
            presenter.detachView(getRetainInstance());
            presenter.onDestroy();
        }
    }


    protected <T extends View> T getView(View view, int resId) {
        return (T) view.findViewById(resId);
    }

    protected abstract P createPresenter();




}